﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Ordens.Communication.Bovespa.Ordens.Motivo;

namespace Sinacor.UI.Bovespa.Ordens.Communication
{
    public class Motivo : BaseCommunication
    {
        #region Construtor

        public Motivo(SessionInformation sessionInformation)
            : base(sessionInformation)
        { }

        #endregion

        #region Metodos

        public void AlterarMotivo(Model.Motivo request)
        {
            IMotivo servico = null;

            try
            {
                using (ServiceInstance<IMotivo> serviceManager = new ServiceInstance<IMotivo>())
                {
                    servico = serviceManager.TryGetInstance(this.Session);
                    servico.AlterarMotivo(Translator.ModelToDataContract.Motivo.ToMotivoRequest(request));
                }

            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

        }

        public void ExcluirMotivo(Model.Parameter.FiltroMotivo request)
        {
            IMotivo servico = null;

            try
            {
                using (ServiceInstance<IMotivo> serviceManager = new ServiceInstance<IMotivo>())
                {
                    servico = serviceManager.TryGetInstance(this.Session);
                    servico.ExcluirMotivo(Translator.ModelToDataContract.Motivo.ToFiltroMotivoRequest(request));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }
        }

        public void IncluirMotivo(Model.Motivo request)
        {
            IMotivo servico = null;

            try
            {
                using (ServiceInstance<IMotivo> serviceManager = new ServiceInstance<IMotivo>())
                {
                    servico = serviceManager.TryGetInstance(this.Session);
                    servico.IncluirMotivo(Translator.ModelToDataContract.Motivo.ToMotivoRequest(request));
                }
            }
            catch (Exception Ex)
            {
                base.HandleFault(Ex);
            }
        }

        public ModelCollection<Model.Motivo> ConsultarMotivos(Model.Parameter.FiltroMotivo request)
        {
            IMotivo servico = null;
            ModelCollection<Model.Motivo> response = null;

            try
            {
                response = new ModelCollection<Sinacor.UI.Bovespa.Ordens.Model.Motivo>();

                using (ServiceInstance<IMotivo> serviceManager = new ServiceInstance<IMotivo>())
                {
                    servico = serviceManager.TryGetInstance(this.Session);
                    response = Translator.DataContractToModel.Motivo.ToMotivo(
                        servico.ConsultarMotivos(Translator.ModelToDataContract.Motivo.ToFiltroMotivoRequest(request)));
                }

            }

            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return response;
        }



        #endregion
    }
}
